package ar.uba.tleng.g99.expregs.automata;


import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

class Node {

	public static final Character LAMBDA = Character.MAX_VALUE;
	
	final Map<Character, Set<Node> > childs;
	
	public Node(){
		this.childs = new HashMap<Character, Set<Node> >();
	}
	
	private synchronized Set<Node> getChilds(Character c) {
		Set<Node> nodes = this.childs.get(c);
		if (nodes == null) {
			nodes = new HashSet<Node>();
			this.childs.put(c, nodes);
		}
		return nodes;
	}
	
	public synchronized void addTransition(Character c, Node n) {
		Set<Node> nodes = getChilds(c);
		nodes.add(n);
	}

	public void mergeChilds(Node c) {
		for (Entry<Character, Set<Node> > e: c.childs.entrySet()) {
			getChilds(e.getKey()).addAll(e.getValue());
		}
	}
}
